tests: Migrate test-pull-many.sh to installed on FAH
authorColin Walters <walters@verbum.org>
Mon, 8 May 2017 17:37:50 +0000 (13:37 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 9 May 2017 15:08:26 +0000 (15:08 +0000)
`test-pull-many.sh` is was just too slow to be a unit test.  Generating
a bunch of files via shell is slow, the delta generation is slow, etc.
Every developer doesn't need to run it every time.

Somewhat address this by converting it into our installed test framework, which
moves it out of the developer fast paths.  Another advantage to this is
that we can simply reuse the FAH tree content rather than synthesizing
new bits each time.

Closes: #840
Approved by: jlebon

Makefile-tests.am
tests/installed/itest-pull.sh [new file with mode: 0755]
tests/installed/libinsttest.sh
tests/test-pull-many.sh [deleted file]

index 14e30b4659c6e8703d5dee071c667678340daeef..335ba9b7bdec9ccff93a4008e5d2a7e3b9e2cbed 100644 (file)
@@ -77,7 +77,6 @@ _installed_or_uninstalled_test_scripts = \
        tests/test-pull-resume.sh \
        tests/test-pull-repeated.sh \
        tests/test-pull-untrusted.sh \
-       tests/test-pull-many.sh \
        tests/test-pull-override-url.sh \
        tests/test-local-pull.sh \
        tests/test-local-pull-depth.sh \
diff --git a/tests/installed/itest-pull.sh b/tests/installed/itest-pull.sh
new file mode 100755 (executable)
index 0000000..e3125f4
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Using the host ostree, test HTTP pulls
+
+set -xeuo pipefail
+
+dn=$(dirname $0)
+. ${dn}/libinsttest.sh
+
+test_tmpdir=$(prepare_tmpdir)
+trap _tmpdir_cleanup EXIT
+
+# Take the host's ostree, and make it archive
+cd /var/srv
+rm repo bare-repo -rf
+mkdir repo
+ostree --repo=repo init --mode=archive
+echo -e '[archive]\nzlib-level=1\n' >> repo/config
+host_nonremoteref=$(echo ${host_refspec} | sed 's,[^:]*:,,')
+ostree --repo=repo pull-local /ostree/repo ${host_commit}
+ostree --repo=repo refs ${host_commit} --create=${host_nonremoteref}
+
+run_tmp_webserver $(pwd)/repo
+# Now test pulling via HTTP (no deltas) to a new bare-user repo
+ostree --repo=bare-repo init --mode=bare-user
+ostree --repo=bare-repo remote add origin --set=gpg-verify=false $(cat ${test_tmpdir}/httpd-address)
+ostree --repo=bare-repo pull --disable-static-deltas origin ${host_nonremoteref}
index 4f72b651c5a2ca545165faec2062e959d416efda..759c95f2edc38ada37a0fd1ff98b2213baf70ae4 100644 (file)
 dn=$(dirname $0)
 . ${dn}/libtest-core.sh
 
+# Copy of bits from tap-test
+test_tmpdir=
+function _tmpdir_cleanup () {
+    if test -n "${test_tmpdir}" && test -f ${test_tmpdir}/.testtmp; then
+             rm "${test_tmpdir}" -rf
+    fi
+}
+prepare_tmpdir() {
+    test_tmpdir=$(mktemp -d)
+    touch ${test_tmpdir}/.testtmp
+    cd ${test_tmpdir}
+    echo ${test_tmpdir}
+}
+
+# This is copied from flatpak/flatpak/tests/test-webserver.sh
+run_tmp_webserver() {
+    dir=$1
+
+    test -n ${test_tmpdir}
+
+    cd ${dir}
+    env PYTHONUNBUFFERED=1 setsid python -m SimpleHTTPServer 0 &>${test_tmpdir}/httpd-output &
+    cd -
+    child_pid=$!
+
+    for x in $(seq 50); do
+        # Snapshot the output
+        cp ${test_tmpdir}/httpd-output{,.tmp}
+        # If it's non-empty, see whether it matches our regexp
+        if test -s ${test_tmpdir}/httpd-output.tmp; then
+            sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output.tmp > ${test_tmpdir}/httpd-port
+            if ! cmp ${test_tmpdir}/httpd-output.tmp ${test_tmpdir}/httpd-port 1>/dev/null; then
+                # If so, we've successfully extracted the port
+                break
+            fi
+        fi
+        sleep 0.1
+    done
+    port=$(cat ${test_tmpdir}/httpd-port)
+    echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
+    echo "$child_pid" > ${test_tmpdir}/httpd-pid
+}
+
 # Determine our origin refspec - we'll use this as a test base
 rpmostree=$(which rpm-ostree 2>/dev/null)
 if test -z "${rpmostree}"; then
diff --git a/tests/test-pull-many.sh b/tests/test-pull-many.sh
deleted file mode 100755 (executable)
index 73245a6..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2017 Colin Walters <walters@verbum.org>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
-set -euo pipefail
-
-. $(dirname $0)/libtest.sh
-
-setup_exampleos_repo
-
-echo '1..3'
-
-cd ${test_tmpdir}
-set -x
-
-echo "$(date): Pulling content..."
-rev=$(${CMD_PREFIX} ostree --repo=ostree-srv/exampleos/repo rev-parse ${REF})
-${CMD_PREFIX} ostree --repo=repo pull --disable-static-deltas origin ${REF}
-${CMD_PREFIX} ostree --repo=repo fsck
-assert_streq ${rev} $(${CMD_PREFIX} ostree --repo=repo rev-parse ${REF})
-
-echo "ok without deltas"
-
-previous=$(${CMD_PREFIX} ostree --repo=repo rev-parse ${rev}^)
-rm repo/refs/{heads,remotes}/* -rf
-${CMD_PREFIX} ostree --repo=repo prune --refs-only
-${CMD_PREFIX} ostree --repo=repo pull origin ${REF}@${previous}
-${CMD_PREFIX} ostree --repo=repo pull --dry-run --require-static-deltas origin ${REF} > output.txt
-assert_file_has_content output.txt 'Delta update: 0/1 parts, 0 bytes/1.[012] MB, 1.[345] MB total uncompressed'
-
-echo "ok delta dry-run"
-
-${CMD_PREFIX} ostree --repo=repo pull  --require-static-deltas origin ${REF}
-assert_streq $(${CMD_PREFIX} ostree --repo=repo rev-parse ${REF}) ${rev}
-${CMD_PREFIX} ostree --repo=repo fsck
-
-echo "ok"